package leetcode;

import java.util.Stack;

/**
 * Leetcode155【最小栈】
 * 链接：https://leetcode-cn.com/problems/min-stack
 */
public class MinStack {
    Stack<Integer> stackActualData = new Stack<>();//实际放数据的栈
    Stack<Integer> stackMinimumData = new Stack<>();//放最小数据的栈
    public MinStack() {

    }

    public void push(int val) {//入栈
        stackActualData.push(val);
        if(stackMinimumData.isEmpty()){
            stackMinimumData.push(val);
        }else {
            stackMinimumData.push(Math.min(stackMinimumData.peek() , val));//比较最小栈的栈顶和当前值傻逼在那拿实际栈比半天
        }
    }

    public void pop() {//出栈
        stackActualData.pop();
        stackMinimumData.pop();
    }

    public int top() {//返回栈顶元素
        return stackActualData.peek();
    }

    public int getMin() {
        return stackMinimumData.peek();

    }
}
